package com.fangcun.service.admin.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fangcun.bean.admin.order.response.SubscribeResponse;
import com.fangcun.bean.sys.PageBean;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.exception.ProValiDataException;
import com.fangcun.entity.OrderCardActivationPerson;
import com.fangcun.entity.OrderCardNumber;
import com.fangcun.mapper.OrderCardActivationPersonMapper;
import com.fangcun.mapper.OrderCardNumberMapper;
import com.fangcun.mapper.OrderSubscribeMapper;
import com.fangcun.service.admin.OrderSubscribeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class OrderSubscribeServiceImpl implements OrderSubscribeService{
	@Autowired
	private OrderSubscribeMapper orderSubscribeMapper;
	
	@Autowired
	private OrderCardNumberMapper orderCardNumberMapper;
	@Autowired
	private OrderCardActivationPersonMapper orderCardActivationPersonMapper;
	/**查询所有卡号**/
	@Override
	public PageInfo<OrderCardNumber> list(PageBean<OrderCardNumber> request)throws ProException {
		PageHelper.startPage(request.getPageNum(), request.getPageSize());
		List<OrderCardNumber> list=orderCardNumberMapper.listForAdmin(request.getParam());
		if(list == null || list.size()==0) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return new PageInfo<>(list);
	}
	/**某卡号关联预定列表**/
	@Override
	public SubscribeResponse details(Long orderDetailId)throws ProException {
		SubscribeResponse request = orderSubscribeMapper.listForAdmin(orderDetailId);
		if( request == null ) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return request;
	}
	
	@Override
	public OrderCardActivationPerson selectByCard(String cardNumber)throws ProException {
		OrderCardActivationPerson request = orderCardActivationPersonMapper.selectByCard(cardNumber);
		if(request==null) {
			throw new ProValiDataException(ErrCode.NO_DATA.getReturnCode(), ErrCode.NO_DATA.getReturnMsg());
		}
		return request;
	}
}
